package Hibernate_web;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;


public class Connector {
    private static Connection conn = null;

    public static Connection getConnection() {
        if (conn == null) {
            try {
                //   Class.forName ("com.mysql.jdbc.Driver").newInstance();
                conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/playerdb", "root", "root");
                System.out.println("Open Connection" + conn.toString());

            } catch (SQLException e) {
                System.out.println(e.getMessage());
                e.printStackTrace();
            }
        }
        System.out.println("Get Connection" + conn.toString());
        return conn;

    }

    @Override
    protected void finalize() throws Throwable {
        super.finalize();
        System.out.println("Close Connection" + conn.toString());
        conn.close();
    }

}
